<?php

/*
  <?php
  class XXX extends Card implements iAction, iKingdom {

  public function __construct() {
  parent::__construct("XXX", Y);
  }

  public function getDescription() {
  return array(
  "",
  "");
  }

  public function play(Game $game, $isRealCard) {

  }

  }
  ?> */

abstract class Card {

    protected $victoryPoints;
    protected $price;
    protected $name;
    protected $value;
    protected $duration;
    protected $undoParams;
    protected $undoPlay;
    protected $undoBuy;

    public function __construct($name, $price, $vp = 0) {
        $this->name = $name;
        if (is_int($price)) {
            $price = new Price($price);
        }
        if (is_array($price)) {
            $price = new Price($price[0], $price[1]);
        }
        if ($price instanceof Price)
            $this->price = $price;
        else {
            throw new Exception("Price is not a class: " . get_class($price));
        }
        $this->victoryPoints = $vp;
        $this->value = new Price();
        $this->duration = 0;
        
        $this->undoPlay = false;
        $this->undoBuy = false;
        $this->undoReaction = false;
    }
    
    public function undoParamsPlay($undoParams) {
        return array($this->undoPlay, $undoParams);
    }
    
    public function undoParamsBuy($undoParams) {
        return array($this->undoBuy, $undoParams);
    }
    
    public function undoParamsReaction($undoParams) {
        return array($this->undoReaction, $undoParams);
    }
    
    public function undo(Game $game, $undoParams) {
        return true;
    }

    public function getFullBasicData($game) {

        $data['name'] = $this->getValue();
        $data['isKingdom'] = $this instanceof iKingdom;
        $data['isAction'] = $this instanceof iAction;
        $data['isTreasure'] = $this instanceof iTreasure;
        $data['isVictory'] = $this instanceof iVictory;
        $data['isCurse'] = $this instanceof iCurse;
        $data['isDuration'] = $this instanceof iDuration;
        $data['isReaction'] = $this instanceof iReaction;
        $data['isRuin'] = $this instanceof iRuin;
        $data['isShelter'] = $this instanceof iShelter;
        $data['isAttack'] = $this instanceof iAttack;
        $data['price'] = $this->getPrice($game)->getData();
        $data['corePrice'] = $this->getPrice(null)->getData();
        $data['description'] = $this->getDescription();
        $data['isImplemented'] = $this->isImplemented();
        $data['imageurl'] = strtolower("pic/" . $this->getKey() . ".jpg");
        return $data;
    }

    public function getData($game) {

        $data['name'] = $this->getValue();
        $data['price'] = $this->getPrice($game)->getData();
        return $data;
    }

    public function getDisplayName($quantity = 1) {
        $d_name = $this->getValue();
        if ($quantity == 1)
            return $d_name;
        else {

            if ($quantity > 1) {
                if ($d_name[strlen($d_name) - 1] == "s") {
                    $d_name = $quantity . " " . $d_name . "es";
                } else if ($d_name[strlen($d_name) - 1] == "y") {
                    $d_name = $quantity . " " . substr($d_name, 0, strlen($d_name) - 1) . "ies";
                } else {
                    $d_name = $quantity . " " . $d_name . "s";
                }
            }
            return $d_name;
        }
    }

    public function getDataAsStr($quantity = 1) {
        $name = $this->getValue();
        $d_name = $this->getDisplayName($quantity);
        return "$name~$d_name";
    }

    public function getKey() {
        return get_class($this);
    }

    public function getValue() {
        return $this->name;
    }

    public function play(Game $game, $isRealCard = true) {
        return true;
    }

    public function buy(Game $game) {
        return true;
    }

    public function trash(Game $game, $name) {
        return true;
    }
    
    public function discard(Game $game, $name) {
        return true;
    }

    // some cards have an effect when they are gained (not necessarily bought)
    public function gainThisCard(Game $game, $name = null) {
        return true;
    }
    
    //some cards (or currently only inn) need to run after the card was gained, and put into the correct pile.
    public function afterGainThisCard(Game $game, $name = null) {
        return true;
    }

    public function cleanup(Game $game) {
        return true;
    }

    // some cards have an effect when they are in play or in player's hand and 
    // other cards are gained
    public function gainOtherCard(Game $game, $card, $name = null) {
        return true;
    }

//    public function afterBuy(Game $game, $card) {
//        return true;
//    }

    public function getVictoryPoints(Game $game, $name) {
        return $this->victoryPoints;
    }

    public function getPrice($game) {
        return $this->price;
    }

    public function setPrice($price) {
        $this->price = $price;
    }

    public function getMoneyValue(Game $game) {
        return $this->value;
    }

    public function setMoneyValue($price) {
        $this->value = $price;
    }

    public function boardSetup(Game $game) {
        return true;
    }

    public function getDescription() {
        return array();
    }

    public function getDuration() {
        return $this->duration;
    }

    public function isImplemented() {
        return true;
    }

    public function isActualCard() {
        return true;
    }

}

?>